package org.BUPT.api.controller;

import lombok.extern.log4j.Log4j2;
import org.BUPT.application.service.MessageService;
import org.BUPT.domain.model.message.MessageBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@Log4j2
@CrossOrigin
public class MessageServiceController {
    @Autowired
    MessageService messageService;
    /**
     * 获取发送到某个用户的所有消息
     * @param userId 用户Id
     * @return 发送的消息列表
     */
    @GetMapping("/getMessage/{userId}")
    public List<MessageBO> getMessage(@PathVariable int userId){
        return messageService.getMessageBOsfUser(userId);

    }
//

    /**
     * 访问一个message（调用这个接口会使message从未读变成已读）
     * @param messageId 需要访问的messageId
     */
    @GetMapping("/Message/{messageId}")
    public void visitMessage(@PathVariable int messageId){
        messageService.visitMessage(messageId);
    }
}
